package cn.iocoder.yudao.module.system.repository.mybatis.dao.user;

import cn.iocoder.yudao.common.pojo.PageResult;
import cn.iocoder.yudao.core.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.core.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.repository.mybatis.domain.user.AdminUser;
import cn.iocoder.yudao.module.system.vo.user.user.UserExportReqVO;
import cn.iocoder.yudao.module.system.vo.user.user.UserPageReqVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface AdminUserMapper extends BaseMapperX<AdminUser> {

    default AdminUser selectByUsername(String username) {
        return selectOne(AdminUser::getUsername, username);
    }

    default AdminUser selectByEmail(String email) {
        return selectOne(AdminUser::getEmail, email);
    }

    default AdminUser selectByMobile(String mobile) {
        return selectOne(AdminUser::getMobile, mobile);
    }

    default PageResult<AdminUser> selectPage(UserPageReqVO reqVO, Collection<Long> deptIds) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AdminUser>()
                .likeIfPresent(AdminUser::getUsername, reqVO.getUsername())
                .likeIfPresent(AdminUser::getMobile, reqVO.getMobile())
                .eqIfPresent(AdminUser::getStatus, reqVO.getStatus())
                .betweenIfPresent(AdminUser::getCreateTime, reqVO.getCreateTime())
                .inIfPresent(AdminUser::getDeptId, deptIds)
                .orderByDesc(AdminUser::getId));
    }

    default List<AdminUser> selectList(UserExportReqVO reqVO, Collection<Long> deptIds) {
        return selectList(new LambdaQueryWrapperX<AdminUser>()
                .likeIfPresent(AdminUser::getUsername, reqVO.getUsername())
                .likeIfPresent(AdminUser::getMobile, reqVO.getMobile())
                .eqIfPresent(AdminUser::getStatus, reqVO.getStatus())
                .betweenIfPresent(AdminUser::getCreateTime, reqVO.getCreateTime())
                .inIfPresent(AdminUser::getDeptId, deptIds));
    }

    default List<AdminUser> selectListByNickname(String nickname) {
        return selectList(new LambdaQueryWrapperX<AdminUser>().like(AdminUser::getNickname, nickname));
    }

    default List<AdminUser> selectListByStatus(Integer status) {
        return selectList(AdminUser::getStatus, status);
    }

    default List<AdminUser> selectListByDeptIds(Collection<Long> deptIds) {
        return selectList(AdminUser::getDeptId, deptIds);
    }

}
